package com.gpt.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.TreeSelect;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.GptTxtClassDetail;import com.gpt.article.service.IGptTxtClassDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类信息Controller
 * 
 * @author zhuzi
 * @date 2023-12-23
 */
@RestController
@RequestMapping("/article/classDetail")
public class GptTxtClassDetailController extends BaseController
{
    @Autowired
    private IGptTxtClassDetailService gptTxtClassDetailService;

    /**
     * 查询分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('article:classDetail:list')")
    @GetMapping("/list")
    public AjaxResult list(GptTxtClassDetail gptTxtClassDetail)
    {
//        startPage();
        List<GptTxtClassDetail> list = gptTxtClassDetailService.selectGptTxtClassDetailList(gptTxtClassDetail);
//        return getDataTable(list);
        List<TreeSelect> jsonlist = gptTxtClassDetailService.selectTxtClassTreeList(gptTxtClassDetail);

        return success(list);
    }






    /**
     * 导出分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('article:classDetail:export')")
    @Log(title = "分类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GptTxtClassDetail gptTxtClassDetail)
    {
        List<GptTxtClassDetail> list = gptTxtClassDetailService.selectGptTxtClassDetailList(gptTxtClassDetail);
        ExcelUtil<GptTxtClassDetail> util = new ExcelUtil<GptTxtClassDetail>(GptTxtClassDetail.class);
        util.exportExcel(response, list, "分类信息数据");
    }

    /**
     * 获取分类信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:classDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gptTxtClassDetailService.selectGptTxtClassDetailById(id));
    }

    /**
     * 新增分类信息
     */
    @PreAuthorize("@ss.hasPermi('article:classDetail:add')")
    @Log(title = "分类信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GptTxtClassDetail gptTxtClassDetail)
    {
        return toAjax(gptTxtClassDetailService.insertGptTxtClassDetail(gptTxtClassDetail));
    }

    /**
     * 修改分类信息
     */
    @PreAuthorize("@ss.hasPermi('article:classDetail:edit')")
    @Log(title = "分类信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GptTxtClassDetail gptTxtClassDetail)
    {
        return toAjax(gptTxtClassDetailService.updateGptTxtClassDetail(gptTxtClassDetail));
    }

    /**
     * 删除分类信息
     */
    @PreAuthorize("@ss.hasPermi('article:classDetail:remove')")
    @Log(title = "分类信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gptTxtClassDetailService.deleteGptTxtClassDetailByIds(ids));
    }
}
